﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ReconUI
{
    public partial class ReconHome : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
			Label lblDateTime = ((Label)Master.FindControl("lblDateTime"));

            if (((UserVO)Session["CurrentUserVO"]) == null)
            {
                Response.Redirect("ReconSignIn.aspx");
            }
            ClientHeading.InnerText = "Invoice Reconciliation System for " + "ABC Ltd.";
            lblDateTime.Text = "Welcome " + ((UserVO)Session["CurrentUserVO"]).userName + "! " + DateTime.Now.ToString();
            //get user details from session object
            UserVO user = ((UserVO)Session["CurrentUserVO"]);

            //populate notifications.
            DBFactory db = new DBFactory();
            
            //unmatched invoice count for operator.
            /*int unmatchedCount = db.GetUnmatchedInvoiceCount(Session[SessionStore.CustomerID].ToString());*/
            int unmatchedCount = db.GetUnmatchedInvoiceCount(user.customerId, 180, 0);
            OperatorNotification180.Text = unmatchedCount.ToString();
            unmatchedCount = db.GetUnmatchedInvoiceCount(user.customerId, 90, 179);
            OperatorNotification90.Text = unmatchedCount.ToString();
            unmatchedCount = db.GetUnmatchedInvoiceCount(user.customerId, 30, 89);
            OperatorNotification30.Text = unmatchedCount.ToString();
            unmatchedCount = db.GetUnmatchedInvoiceCount(user.customerId, 0, 29);
            OperatorNotification0.Text = unmatchedCount.ToString();
            if (OperatorNotification180.Text =="0" &&  OperatorNotification90.Text =="0" &&  OperatorNotification30.Text =="0" &&  OperatorNotification0.Text == "0")
            {
                MatchAction.Disabled = true;
            }

            //unauthorized invoice count for supervisor.
            /*int unauthorizedCount = db.GetUnauthorizedInvoiceCount(Session[SessionStore.CustomerID].ToString());*/
            int unauthorizedCount = db.GetUnauthorizedInvoiceCount(user.customerId, 180, 0);
            SupervisorNotification180.Text = unauthorizedCount.ToString();
            unauthorizedCount = db.GetUnauthorizedInvoiceCount(user.customerId, 90, 179);
            SupervisorNotification90.Text = unauthorizedCount.ToString();
            unauthorizedCount = db.GetUnauthorizedInvoiceCount(user.customerId, 30, 89);
            SupervisorNotification30.Text = unauthorizedCount.ToString();
            unauthorizedCount = db.GetUnauthorizedInvoiceCount(user.customerId, 0, 29);
            SupervisorNotification0.Text = unauthorizedCount.ToString();
            if (SupervisorNotification180.Text == "0" && SupervisorNotification90.Text == "0" && SupervisorNotification30.Text == "0" && SupervisorNotification0.Text == "0")
            {
                AuthorizeAction.Disabled = true;
            }

            //unmatched invoice count for remitter.
            int unmatchedCountForRemitter = db.GetUnmatchedInvoiceCountForRemitter(user.customerId, user.userId, 180, 0);
            RemitterNotification180.Text = unmatchedCountForRemitter.ToString();
            unmatchedCountForRemitter = db.GetUnmatchedInvoiceCountForRemitter(user.customerId, user.userId, 90, 179);
            RemitterNotification90.Text = unmatchedCountForRemitter.ToString();
            unmatchedCountForRemitter = db.GetUnmatchedInvoiceCountForRemitter(user.customerId, user.userId, 30, 89);
            RemitterNotification30.Text = unmatchedCountForRemitter.ToString();
            unmatchedCountForRemitter = db.GetUnmatchedInvoiceCountForRemitter(user.customerId, user.userId, 0, 29);
            RemitterNotification0.Text = unmatchedCountForRemitter.ToString();
            if (RemitterNotification180.Text == "0" && RemitterNotification90.Text == "0" && RemitterNotification30.Text == "0" && RemitterNotification0.Text == "0")
            {
                RemitterMatchAction.Disabled = true;
            }

            lblPreviousLogin.Text = System.DateTime.Now.AddDays(-1).ToString("dd/MM/yyyy") + " " + System.DateTime.Now.AddHours(-2).AddMinutes(-37).ToShortTimeString();
            lblCurrentLogin.Text = System.DateTime.Now.ToString("dd/MM/yyyy") + " " + System.DateTime.Now.ToShortTimeString();
            lblUserType.Text = user.userType;

        }
    }
}